package com.gws.ievent.scheduler;

import com.gws.ievent.common.utils.DefaultThreadFactory;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author song
 * @date 2022/10/21 21:19
 */
public enum ThreadPoolExecutorInstance {

    /**
     * 线程池单例
     */
    INSTANCE;
    private final ThreadPoolExecutor threadPoolExecutor;


    ThreadPoolExecutorInstance() {
        threadPoolExecutor = new ThreadPoolExecutor(
                SchedulerConfig.getInstance().getCorePoolSize(),
                SchedulerConfig.getInstance().getMaximumPoolSize(),
                SchedulerConfig.getInstance().getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                new DefaultThreadFactory(SchedulerConfig.getInstance().getThreadPoolThreadName())
        );
    }

    public ThreadPoolExecutor instance() {
        return this.threadPoolExecutor;
    }

}
